package com.isoftstone.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isoftstone.mapper.NoticeMapper;
import com.isoftstone.pojo.Notice;
import com.isoftstone.service.NoticeService;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    @Override
    public Page queryAllNotices(Integer currentPage, Integer pageSize, String title) {
        Page< Notice> page = new Page<>(currentPage, pageSize);
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        if (title != null && !title.isEmpty()){
            queryWrapper.like("title", title);
        }
        queryWrapper.orderByDesc("create_time");
        return baseMapper.selectPage(page, queryWrapper);
    }

    @Override
    public boolean insertNotice(Notice notice) {
        return save( notice);
    }

    @Override
    public boolean updateNotice(Notice notice) {
        return updateById(notice);
    }

    @Override
    public boolean deleteNotice(Integer id) {
        return removeById(id);
    }
}
